def batch_n(v, batch=20):
    if isinstance(v,dict):
        mm = len(v)
        nm = int(mm / batch)
        if nm * batch != mm:
            nm = nm + 1
        keys=list(v.keys())
        for i in range(nm):
            n = i * batch
            m = n + batch
            s={}
            for k in keys[n:m]:
                s[k]=v[k]
            yield s
    else:
        mm = len(v)
        nm = int(mm / batch)
        if nm * batch != mm:
            nm = nm + 1
        for i in range(nm):
            n = i * batch
            m = n + batch
            yield v[n:m]
def split_n(l,n):
    rst=[]
    if not l:
        return l
    if isinstance(l,dict):
        m=0
        nn=len(l)/n
        t={}
        for k,v in l.items():
            m=m+1
            t[k]=v
            if m>=nn:
                rst.append(t)
                t={}
                m=0
        if t:
            rst.append(t)
    else:
        for i in range(0,len(l),n):
            rst.append(l[i:i+n])
    return rst
if __name__=="__main__":
    l=split_n({"a":1,"b":2,"c":3,"d":4,"e":5},2)
    print(l)
